<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
		<title>运维管理平台</title>
		<link rel="icon" href="/static/favicon.ico" sizes="64x64" />
		<style>
			html {
      height: 100%;
    }

    body {
      background-color: #ffffff;
      margin: 0px;
      height: 100%;
      color: #555;
      font-family: 'inconsolata';
      font-size: 15px;
      /* line-height: 18px; */
      overflow: hidden;
    }

    .el-notification.left {
      left: 60px !important;
    }

    #progress {
      height: 1px;
      display: inline-block;
      background-color: #0078D7;
      box-shadow: 0 0 5px 2px #0078D7;
      width: 0;
      position: fixed;
      left: 0;
      top: 0;
      z-index: 9999;
      border-radius: 5px;
    }

    .el-dropdown {
      vertical-align: top;
    }

    .el-dropdown+.el-dropdown {
      margin-left: 0px;
    }

    .el-icon-arrow-down {
      font-size: 12px;
    }

    #viewer3d {
      position: absolute;
      border: 0px;
      left: 0px;
      top: 0px;
      width: 100%;
      height: 100%;
      z-index: 1;
      /* overflow: scroll; */
    }

    .clickRightMenu {
      width: 159px;
      font-size: 12px;
      position: absolute;
      text-align: left;
      padding: 2px 0;
      border: 1px solid #ccc;
      /* display: none; */
      z-index: 100;
      background: rgba(255, 255, 255, 1);
      border-radius: 4px;
      box-shadow: 0px 4px 8px 0px rgba(0, 0, 0, 0.35);
      font-family: Microsoft YaHei Regular;
    }

    .clickRightMenu li {
      list-style: none;
      line-height: 28px;
      font-size: 14px;
      text-align: left;
      padding: 5px 30px;
    }

    .clickRightMenu li:hover {
      background-color: #2d61a8;
      cursor: pointer;
      color: white;
      border-radius: 2px;
    }

    .measure {
      position: absolute;
      right: 300px;
      bottom: 15px;
      background: #fff;
      border-radius: 5px;
      box-shadow: 0 1px 9px rgba(0, 0, 0, 0.3);
      width: 280px;
      min-height: 140px;
      letter-spacing: 2px;
    }

    .measure span {
      display: block;
      text-align: center;
      height: 20px;
      line-height: 20px;
      padding: 10px;
      background: #0078D7;
      color: #fff;
    }

    .measure span i {
      font-style: normal;
      font-size: 10px;
      float: right;
      cursor: pointer;
    }

    .measure p {
      display: block;
      padding: 10px;
      color: #333;
      font-size: 14px;
    }

    .engine-modal {
      position: absolute;
      z-index: 100000;
      left: 0px;
      top: 40px;
      bottom: 0px;
      right: 0px;
      background: url(/static/img/background_01.jpg) no-repeat center;
      background-size: cover;
      z-index: 200;
      padding: 0 0 0 40px;
    }

    .group {
      display: flex;
      flex-direction: row;
    }

    .group-item {
      background: #E4EBF5;
      margin-left: 20px;
      margin-top: 20px;
      font-size: 16px;
      color: #6D8599;
      width: 200px;
      height: 110px;
      padding: 15px 0px 0 20px;
      border-radius: 4px;
      box-shadow: 0 0 2px #0078D7;
    }

    .factoryNum {
      font-size: 60px;
      color: #0078D7;
    }

    .group-item.right {
      width: 280px;
      height: 110px;
      position: relative;
    }

    .group-item.right span {
      position: absolute;
      top: 0;
      left: 0;
      bottom: 0;
      right: 0;
    }

    .engine {
      margin-right: 0.2rem;
      position: absolute;
      z-index: 2000;
      top: 7px;
      right: 345px;
      cursor: pointer;
    }

    s {
      text-decoration: none;
      font-size: 8px;
      border: 1px solid #fff;
      color: #fff;
      border-radius: 4rem;
      padding: 1px 4px;
    }

    .tag-btns {
      display: flex;
      border-radius: 4px;
      background: rgba(255, 255, 255, .9);
      font-size: 14px;
    }

    .del-btn,
    .view-btn {
      cursor: pointer;
      color: #0078D7;
      padding: 4px 5px;
    }

    .view-btn:hover {
      color: #fff;
      background: #0078D7;
    }

    .del-btn:hover {
      color: #fff;
      background: #0078D7;
    }

    #view_tag {
      width: 500px;
      /* height: 200px; */
      position: absolute;
      left: 10%;
      top: 15%;
      display: none;
      z-index: 2;
    }

    #view_img {
      display: block;
      width: 100%;
    }

    #close_view {
      cursor: pointer;
      position: absolute;
      font-style: normal;
      right: -30px;
      color: #fff;
      display: block;
      width: 20px;
      height: 20px;
      border-radius: 50%;
      border: 2px solid #fff;
      line-height: 20px;
      text-align: center;
    }

    #close_view:hover {
      border-color: #0078D7;
      color: #0078D7;
    }
	
	.tips_show {
		border-radius: 8px;
		background: rgba(34, 52, 85, 0.6);
		width: 100px;
		height: 32px;	
	}
	
	.tips_parent {
		position: relative;
		display: flex;
		flex-direction: row;
	}
	
	.tip-icon {
	  width: 32px;
	  height: 32px;
	  border-radius: 8px;
	}
	
	.tips-cont {
		width: calc(130px - 48px);
		padding: 2px;
	}
	
	.p-text-first {
		font-size: 12px;
		color: #ffffff;
		overflow: hidden;
		margin-top: 0;
		margin-bottom: 0;
	}
	
	.p-text-other {
		font-size: 9px;
		color: #ffffff;
		overflow: hidden;
		margin-top: 2px;
		margin-bottom: 0;
	}
	
	.video-img {
	  width: 35px;
	  height: 49px;
	  background: url('./img/video_unsel.png') no-repeat center;
	  background-size: contain;
	}
	
	.cctv-tip {
	  display: flex;
	  flex-direction: column;
	  align-items: center;
	  /* cursor: pointer; */
	}
	
	.cctv-title {
	    margin-top: 2px;
	    color: #fff;
	    font-size: 10px;
	    background: rgba(0,0,0,0.2);
	    padding: 5px;
	    border-radius: 10px;
	  }
	
  </style>


	</head>


	<script src="./js/indexedDB/indexedDB.js"></script>
	<script src="./js/build.js"></script>
	<script src="./js/3dEngine/js/3dEngine.js"></script>
	<script src="./js/js/free.player.1.8.js"></script>
	<script src="./js/config.js"></script>
	<!-- <script src="http://tianqi.2345.com/t/7day_tq_js/71146.js" charset="gbk"></script> -->
	<!-- built files will be auto injected -->
	<script type="text/javascript">
		// statrt ######  ios专用
		// (function () {
		//   var dw = document.createElement("script");
		//   dw.src = "https://static.bufanapp.com/pack.js?18ba440d6bf7492a8a1567811747cab5"
		//   var s = document.getElementsByTagName("script")[0];
		//   s.parentNode.insertBefore(dw, s);
		// })()
		// end ######  
		console.log("web js head")
		var a = 0;

		function model_ENV_Change(userObj) {
			console.log("model_ENV_Change start")
			let delModelId = ''
			if (userObj.Account.includes('ncs-')) {
				// document.write('<script src="/static/3dEngine/js/3dEngine2.js" type="text/javascript" ></sc' + 'ript>')
				delModelId = window.spc_config.modelId
			} else {
				// script.src = "/static/3dEngine/js/3dEngine.js";
				// document.write('<script src="/static/3dEngine/js/3dEngine.js" type="text/javascript" ></sc' + 'ript>')
				delModelId = window.mahe_config.modelId
			}
			RemoveEnvModel()
			RemoveModel(delModelId)
			console.log("model_ENV_Change  AddModel")
			console.log("AddModel " + window.R_config.modelJsonUrl)
			AddModel(window.R_config.modelJsonUrl, window.R_config.modelId)

			console.log("AddEnvModel " + window.R_config.modelURL)
			AddEnvModel(window.R_config.modelURL, window.R_config.modelX, window.R_config.modelY, window.R_config.modelZ)
		}

		function changeConfig(user) { //根据用户修改config
			if (user.Account.includes('ncs-')) {
				window.R_config = JSON.parse(JSON.stringify(window.mahe_config))
			} else {
				window.R_config = JSON.parse(JSON.stringify(window.spc_config))
			}
		}
		(function(designWidth, maxWidth) {
			// animationFrame()
			window.spc_config = window.R_config
			window.mahe_config = window.mh_config
			if (localStorage.user) {
				let user = JSON.parse(localStorage.user)
				window.changeConfig(user)
			}
			var doc = document,
				win = window;
			var docEl = doc.documentElement;
			var tid;
			var rootItem, rootStyle;

			function refreshRem() {
				var width = docEl.getBoundingClientRect().width;
				if (!maxWidth) {
					maxWidth = 540;
				};
				if (width > maxWidth) {
					width = maxWidth;
				}
				var rem = width * 100 / designWidth;
				rootStyle = "html{font-size:" + rem + 'px !important}';
				rootItem = document.getElementById('rootsize') || document.createElement("style");
				if (!document.getElementById('rootsize')) {
					document.getElementsByTagName("head")[0].appendChild(rootItem);
					rootItem.id = 'rootsize';
				}
				if (rootItem.styleSheet) {
					rootItem.styleSheet.disabled || (rootItem.styleSheet.cssText = rootStyle)
				} else {
					try {
						rootItem.innerHTML = rootStyle
					} catch (f) {
						rootItem.innerText = rootStyle
					}
				}
				docEl.style.fontSize = rem + "px";
			};
			refreshRem();
			win.addEventListener("resize", function() {
				clearTimeout(tid);
				tid = setTimeout(refreshRem, 300);
			}, false);
			win.addEventListener("pageshow", function(e) {
				if (e.persisted) {
					clearTimeout(tid);
					tid = setTimeout(refreshRem, 300);
				}
			}, false);
			if (doc.readyState === "complete") {
				doc.body.style.fontSize = "16px";
			} else {
				doc.addEventListener("DOMContentLoaded", function(e) {
					doc.body.style.fontSize = "16px";
				}, false);
			}
		})(1334, 1334);
	</script>

	<body>
		<!-- <video id="video" loop crossOrigin="anonymous" webkit-playsinline style="display:none"> -->
		<!-- <source src="/static/3dEngine/images/company.mp4" type='video/mp4; codecs="avc1.42E01E, mp4a.40.2"'> -->
		<!-- </video> -->
		<!-- <video id="video2" autoplay style="display:none"></video> -->

		<div id="viewer3d"></div>

		<!-- 		<button style="position: absolute;top: 50vh;" class="clickMe" type="button" id="clickMe">
			点击我给 APP 传递参数
		</button> -->

		<!-- 		<button style="position: absolute;top: 50vh;z-index: 10;" class="clickMe" type="button" id="clickMe">
			点击我
		</button> -->
	</body>

	<script type="text/javascript" src="https://js.cdn.aliyun.dcloud.net.cn/dev/uni-app/uni.webview.1.5.2.js"></script>
	<!-- JSbridge -->
	<script src="js/uni-js-bridge.es5.js" type="text/javascript" charset="utf-8"></script>
	<script>
		console.log("web js bottom")

		var measureType = '';
		var IpAddress = '127.0.0.1';
		var bCtrl = false;
		var elementType = 0; //0为颜色，1为半透明，2为隐藏
		var modelName = 'rst';
		var nameArray = ['spc1210'];
		var modelArray = [];
		var currentIndex = 0;
		var clickMode = '';
		// var measureIndex = 0;
		var flyArray = [];
		var currentElement = '';
		var clickGlids = ''
		var currentPos = '';
		var markerArray = [];
		var cctvMarkerArray = [];
		var meterArray = [];
		var gridArray = [];
		var Muster = ''; //集合
		var markerviewArray = [];
		var measureResult = [];
		var testview = '';
		var bWireFrame = false;
		var modelLocationList = [];
		var tagId = '';
		var tagData = '';
		var delMarker = [];
		var delMarkPer = false;
		var tagImg = '';

		// add
		var searchTag = false;
		var CID = '';
		var PData = null;
		var lang = '';
		var dcsArray = [];
		var dcsmarker = [];


		$(function() {

			const lang = ['en', 'zh', 'jap'];
			const name = [{
				lang: 'Open 3D',
				lang1: "Close 3D"
			}, {
				lang: '开启三维',
				lang1: "关闭三维"
			}, {
				lang: '3Dを開く',
				lang1: "3Dを閉じる"
			}];

			const htmlTitle = ['Operation and maintenance management platform', '运维管理平台', '運用保守管理プラットフォーム'];

			function getCookie(name) {
				var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
				if (arr = document.cookie.match(reg))
					return unescape(arr[2]);
				else
					return null;
			};
			var index = lang.indexOf(getCookie('lang'));
			const obj = name[index];


			// $('.engine').find('s').text(obj['lang']);



			$(document).attr('title', htmlTitle[index])
			// getCookie('lang')
			var indey = 0;
			$('.engine').on("click", function() {
				console.log($(this).html())
				const flag = $(this).attr('data-flag');
				flag == 'true' ? (async () => {
					$(this).attr('data-flag', 'false')
					$('.engine-modal').fadeOut();
					$('.engine').find('s').text(obj['lang1']);
				})() : (async () => {
					$(this).attr('data-flag', 'true');
					$('.engine-modal').fadeIn();
					//  $(this).find('s').html('开启三维');
					$('.engine').find('s').text(obj['lang']);
				})();
				$(this).attr('data-flag') == 'true' ? (async () => {
					indey++;
					indey > 4 ? indey = 1 : indey;
					$('.engine-modal').css("background-image", 'url(/static/img/background_0' + indey + '.jpg)')
				})() : (async () => {

				})()
			});



			// $.ajax({
			// 	type: "POST",
			// 	//请求的媒体类型
			// 	contentType: "application/json;charset=UTF-8",
			// 	//请求地址
			// 	url: window.R_config.spc_url + '/api/Collections/GetFactoryDate',
			// 	//数据，json字符串
			// 	data: '',
			// 	//请求成功
			// 	success: function(result) {
			// 		result.code == 0 ? $('.factoryNum').text(result.data) : '';
			// 	},
			// 	//请求失败，包含具体的错误信息
			// 	error: function(e) {
			// 		// console.log(e.status);
			// 		// console.log(e.responseText);
			// 	}
			// })
		})
		// if ((localStorage.isReload == "false")) {

		console.log("AddModel  init")
		console.log("AddModel " + window.R_config.modelJsonUrl)
		AddModel(window.R_config.modelJsonUrl, window.R_config.modelId);
		// }
		// window.document.onkeydown = function() {

		// 	if (window.event.ctrlKey) {
		// 		bCtrl = true;
		// 	}
		// 	if (window.event.shiftKey) {
		// 		StartRectCheck();
		// 	}
		// }

		// window.document.onkeyup = function() {
		// 	if (!window.event.ctrlKey) {
		// 		bCtrl = false;
		// 	}
		// 	if (!window.event.shiftKey) {
		// 		CloseRectCheck();
		// 	}
		// }
		var t = Date.now();

		function sleep(d) {
			while (Date.now - t <= d);
		}

		var xtest = 0;

		function myclip() {
			xtest += 0.1;
			PlateClip('x-min', xtest);
		}

		// 视角cuble显示
		EngineConfig("viewer3d", false);
		SetShowNum(6); //控制每次动态加载的切片数量，如果觉得加载时间长就调小一点
		//SetShowNum(100);
		SetBackColor(118, 184, 249, 1.0);
		//SetMouseMode(1);
		function resetView() {
			SetCameraMode(0)
			ResetViewPort()
			// SetPivot('1187417.0083951748,1148509.359201031,-1.4551915228366852e-11')
			SetView(window.R_config.initView)
			SetZoomSpeed(1)
		}

		function pt_TouchToClick(dom, derect, callback) {
			$("body").on('touchstart', dom, function(event) {
				let x = 0,
					x1 = 0,
					flag = 0,
					atrsy = !derect ? "pageX" : "pageY",
					e = event || window.event;
				x = e.targetTouches[0][atrsy];
				$(this).on("touchend", function(event) {
					let e = event || window.event;
					x1 = e.changedTouches[0][atrsy], flag = x != x1 ? 0 : 1;
				})
				setTimeout(() => {
					flag && callback.call(this);
				})
			})
		}

		function onHtmlClick() {

		}

		function onMeterClick(val) {
			vm.$store.state.eqData = {
				DeviceName: 'LT-1290',
				Type: 1
			}
			vm.$store.commit('showModal', {
				name: 'meterHistory',
				show: true,
				left: '380px',
				top: '620px',
				data: null
			})
		}

		function onLabelClick(val,glids) {
			FlyTo(glids, true, 2.8);
			OnElementSelected(glids)
			// alert("onLabelClick:" + glids );
			vm.$store.state.eqData = {
				DeviceName: val,
				Type: 1
			}
			vm.$store.commit('showModal', {
				name: 'eqHistory',
				show: true,
				left: '',
				top: '1rem',
				data: null
			})
		}
		var rightClick = null

		function OnClickPositionByRightMouse(position) {
			currentPos = position;
			console.log('rightClick' + position);
			rightClick = 0
			//console.log(GetDistanceFromCamera(currentPos));
		}

		function OnClickPosition(position) {
			// rightClick = null
			// clickMode = ''
			currentPos = position;
			// console.log('点击位置' + position);
		}

		function OnLodProcess() {
			//SetClickMode(0);
		};

		function OnLodFinish() {
			console.log("index.html:OnLodFinish")

			//SetClickMode(3);
			if (elementType == 0) {
				console.log(clickGlids)
				SetElementColor(currentElement || clickGlids, 255, 0, 0);
			} else if (elementType == 1) {
				SetElementColor(currentElement, 255, 255, 0);
			} else if (elementType == 2) {
				SetElementColor(currentElement, 0, 0, 255);
			} else if (elementType == 3) {
				SetElementColor(currentElement, window.rustColor[0], window.rustColor[1], window.rustColor[2]);
				window.elementType = 0
			}
		};

		function OnModelLoaded(tag) {
			console.log("index.html:OnModelLoaded")
			modelArray.push(tag)
			console.log("test - 00")
			let user = null
			// if (localStorage.user) {
			// 	user = JSON.parse(localStorage.user)
			// } else {
			// 	return
			// }
			console.log("test - 11")
			if (currentIndex < nameArray.length - 1) {
				currentIndex++;
				console.log("OnModelLoaded  AddModel")
				console.log("AddModel " + window.R_config.modelJsonUrl)
				AddModel(window.R_config.modelJsonUrl, window.R_config.modelId)
			} else {
				AddEnvModel(window.R_config.modelURL, window.R_config.modelX, window.R_config.modelY, window.R_config.modelZ)

				// if (!user.Account.includes('ncs-')) {
				// 	console.log("ncs-AddEnvModel " + window.R_config.modelURL)
				// 	AddEnvModel(window.R_config.modelURL, window.R_config.modelX, window.R_config.modelY, window.R_config.modelZ)
				// 	AddFire('923271.3086911268,1082499.6066213774,48500')
				// } else {
				// 	// AddModel(window.R_config.modelJsonUrl, window.R_config.modelId)
				// 	console.log("else-AddEnvModel " + window.R_config.modelURL)
				// 	AddEnvModel(window.R_config.modelURL, window.R_config.modelX, window.R_config.modelY, window.R_config.modelZ)
				// }
				// // SetSkyBox('/static/3dEngine/images/dawnmountain/')
				SetView(window.R_config.initView)
				console.log("window.R_config.initView = " + window.R_config.initView)
				// ClipAnimation('z-max', 1.0, 0.0, 5000);

				UniJsBridge.callHandler(
					"nativeShow", {
						page: "web-index",
						action: "init-over"
					},
					res => {
						console.log("callHandler - init-tags - sendback : ")
						console.log(res)
					}
				);
			}
		}

		function getBitNumbers(guids) {
			$.ajax({
				url: window.R_config.spc_url + '/api/ModelDataSPC/GetModelData',
				type: 'POST',
				async: false,
				contentType: 'application/json;charset=utf-8',
				headers: {
					'Access-Control-Allow-Origin': '*'
				},
				data: JSON.stringify({
					glid: guids,
					BitNumber: '',
					MileageID: window.R_config.modelId
				}),
				dataType: 'json',
				success: (data) => {
					if (data.code === 0) {
						goujianListId = data.data.glid
						currentElement = goujianListId.join('#');
						clickGlids = goujianListId.join('#');
						Muster = data.data.BitNumber;
					} else {
						currentElement = guids;
						clickGlids = guids;
						Muster = '';
					}
					console.log(clickGlids)

					// console.log("MusterMusterMusterMuster",Muster)
					// SetElementColor(currentElement, 255, 0, 0);
				},
				error: () => {
					return false
				}
			})
		}

		function getDefaultView() {
			$.ajax({
				url: window.R_config.spc_url + '/api/ViewManagement/GetViewManageList',
				type: 'POST',
				async: false,
				contentType: 'application/json;charset=utf-8',
				headers: {
					'Access-Control-Allow-Origin': '*'
				},
				data: JSON.stringify({
					MileageID: window.R_config.modelId
				}),
				dataType: 'json',
				success: (data) => {
					data.data.map(n => {
						if (n.IsDefault) {
							window.R_config.initView = n.Position
						}
					})
				}
			})
		}

		function getBitGid(val) {
			$.ajax({
				url: window.R_config.spc_url + '/api/PidSvg/GetBitGId',
				type: 'POST',
				async: false,
				contentType: 'application/json;charset=utf-8',
				headers: {
					'Access-Control-Allow-Origin': '*'
				},
				data: JSON.stringify({
					Glid: '',
					BitNumber: val,
					MileageID: window.R_config.modelId
				}),
				dataType: 'json',
				success: (data) => {
					if (data.code === 0) {
						console.log(data)
						window.svgFUNC.cTDG(data.data[0].BitNumber, data.data[0].GId)
					}
					// console.log("MusterMusterMusterMuster",Muster)
					// SetElementColor(currentElement, 255, 0, 0);
				},
				error: () => {
					return false
				}
			})
		}

		function OnElementSelected(id) {
			// if (id == window.R_config.floorId) return
			console.log('构件id---' + id)
			getBitNumbers(id)
			PData = {
				type: "getproperty",
				data: {
					id: id
				}
			}
			// if (document.getElementById('dwgpreview')) {
			// 	// console.log(Muster)
			// 	getBitGid(Muster)
			// }
			var strs = new Array()
			strs = id.toString().split("_");

			if (!bCtrl) {
				ResetAllElement();
			}
			//return;
			//ClearHighLight();
			// console.log('构建ID集合---' + currentElement)
			if (elementType == 0) {
				SetElementColor(currentElement || clickGlids, 255, 0, 0);
			} else if (elementType == 1) {
				SetElementColor(currentElement, 255, 255, 0);
			} else if (elementType == 2) {
				SetElementColor(currentElement, 0, 0, 255);
			} else if (elementType == 3) {
				SetElementAlpha(currentElement, 0.4);
			} else if (elementType == 4) {
				SetElementVisible(currentElement, false);
			}
			var strs1 = new Array();
			strs1 = id.toString().split("#");
			
			UniJsBridge.callHandler(
				"nativeShow", {
					page: "web-index",
					action: "click-bit",
					Muster:Muster,
				},
				res => {
					console.log("callHandler - sendback : ")
					console.log(res)
				}
			);
			
		}

		function OnClickBlank() {
			console.log('blank');
		};

		function closeMeasure() {
			var dom = document.getElementById('measure')
			dom.style.display = "none"
		};

		function OnMeasureResult(result) {
			console.log(result)
			var rArray = new Array();
			rArray = result.toString().split(",");
			var dom = document.getElementById('measure')
			dom.style.display = "block"
			var measureValue = document.getElementById('measureTxt')
			if (measureType == '0') {
				measureValue.innerText = '两点距离为' + rArray[0] + '米(紫色线条),' + '两点X轴距离为' + rArray[1] + '米(红色线条),' + '两点Y轴距离为' + rArray[
					2] + '米(绿色线条)，' + '两点Z轴距离为' + rArray[3] + '米(蓝色线条)'
			} else if (measureType == '1') {
				measureValue.innerText = '角度为' + rArray[0] + '度'
			} else if (measureType == '2') {
				measureValue.innerText = '面积为' + rArray[0] + '平方米'
			} else if (measureType == '3') {
				measureValue.innerText = '体积为' + rArray[0] + '立方米'
			} else if (measureType == '4') {
				dom.style.display = "none"
			}
		};

		function OnHtmlUpdate() {
			if (delMarker.length > 0) {
				RemoveMarker(delMarker[0])
				delMarker = []
			}
			var divPos = Get2dPosBy3dPos(currentPos)
			var getScale = 1 - (GetDistanceFromCamera(currentPos) - 3000) / 200000
			// var rightMenu = document.getElementById('clickRightMenu');
			// rightMenu.style.left = divPos[0] + "px";
			// rightMenu.style.top = divPos[1] + "px";
			if (meterArray.length > 0) {
				var meters = ''
				var meterPos = ''
				for (var i = 0; i < meterArray.length; i++) {
					meters = document.getElementById(meterArray[i].id)
					var distance = GetDistanceFromCamera(meterArray[i].pos)
					// meterPos = Get2dPosBy3dPos(meterArray[i].pos)
					// console.log(meterArray[i].id, distance)
					if (distance > 70000) {
						getScale = 0
					} else {
						getScale = 1 - (70000 - distance) / 100000
					}
					// console.log(getScale)
					if (getScale >= 0) {
						meters.style.transform = 'scale(' + getScale + ')'
						meters.style.opacity = '1'
						// meters.style.right = meterPos[0] + 'px'
						// meters.style.bottom = meterPos[1] + 'px'
					}
				}
			}
		}

		function deleteTag() {
			$.ajax({
				url: window.R_config.spc_url + '/api/warnMark/DelWarnMark',
				type: 'POST',
				async: false,
				contentType: 'application/json;charset=utf-8',
				headers: {
					'Access-Control-Allow-Origin': '*'
				},
				data: JSON.stringify({
					ID: tagId
				}),
				dataType: 'json',
				success: (data) => {
					if (data.code === 0) {
						console.log(data)
						RemoveMarker(JSON.stringify(tagData))
						for (var i = 0; i < delMarker.length; i++) {
							RemoveMarker(delMarker[i])
						}
						markerArray = []
					}
				},
				error: () => {
					return false
				}
			})
		}

		function viewTag() {
			var viewDiv = document.getElementById('view_tag')
			var viewImg = document.getElementById('view_img')
			viewDiv.style.display = 'block'
			viewImg.setAttribute('src', tagImg)
		}

		function closeView() {
			var viewDiv = document.getElementById('view_tag')
			viewDiv.style.display = 'none'
		}

		function OnMarkerClick(result) {
			if (delMarker.length > 0) {
				for (var i = 0; i < delMarker.length; i++) {
					RemoveMarker(delMarker[i])
				}
				delMarker = []
			}
			console.log(result)
			// console.log(JSON.parse(result) instanceof Object)
			// console.log(delMarkPer)
			if (JSON.parse(result) instanceof Object && delMarkPer) {
				tagData = JSON.parse(result)
				tagId = tagData.id
				tagImg = tagData.img
				var htmlStr =
					`<div class="tag-btns">
        <div class="del-btn" onclick='deleteTag()'>删除标签</div>
        <div class="view-btn" onclick='viewTag()'>预览标签</div>
        </div>`;
				AddHtmlMarker(tagData.pos, htmlStr, 'delmarker' + delMarker.length);
				delMarker.push('delmarker' + delMarker.length)
				// deleteTag(result)
			}
		}

		function TestFun() {
			TestFunction();
		}

		function OnGridIntersectionClick(result) {
			var rArray = new Array();
			rArray = result.toString().split(",");
			// myapp.$notify({
			//   title: '当前位置',
			//   message: '\'' + rArray[0] + '\'轴线与\'' + rArray[1] + '\'轴线的交点',
			//   duration: 5000,
			//   offset: 50,
			//   type: 'success'
			// });

		};

		function Refresh() {
			SetCameraMode(0);
			ResetClip();
			StopViewAnimation();
			SetView(
				"1158763.2832010626,1125886.6690360513,0,-10891.872935237876,-612305.0142375432,12966.5153990929,-0.5603981633974479,-0.6499814967307813"
			)
			// this.clipValue1 = [0, 100];
			// this.clipValue2 = [0, 100];
			// this.clipValue3 = [0, 100];
			ResetAllElement();
			// ResetViewPort();
			StopMeasure();
			Blow(0);
			for (var i = 0; i < nameArray.length; i++) {
				SetModelNomal('tag' + i);
			}
			for (var i = 0; i < markerArray.length; i++) {
				RemoveMarker(markerArray[i]);
			}
			markerArray = [];
			if (delMarker.length > 0) {
				for (var i = 0; i < delMarker.length; i++) {
					RemoveMarker(delMarker[i])
				}
				delMarker = []
			};
			document.getElementById('measure').style.display = 'none'
		}

		console.log("index.html:load end")

		/**
		 * 在H5端配置一个默认处理函数，提供给uni-app调用
		 */
		UniJsBridge.init((data, responseCallback) => {
			if (data.page == "uni-home") {
				if (data.action == "afterinit") {
					ResetAllElement()
					RemoveMarker('devTag')
				} else if (data.action == "search-point") {
					alert("search-point " + data.params.glids )
					FlyTo(data.params.glids, true, 2.8)
					SetElementColor(data.params.glids, 255, 0, 0)
				} else if (data.action == "select-pos") {
					elementType = 0;
					clickGlids = data.params.glids;
					currentElement = data.params.glids;

					if (document.getElementById("QValue_" + data.params.row.ID) == null)
						addLabel(data.params.row, data.params.glids, "mutiple");
					else
						showDetail(data.params.row, data.params.glids, "mutiple");
					// console.log(clickGlids)
				} else if (data.action == "remove-realdata-tags") {
					hideAllTags();
				}  else if (data.action == "hide-all-tags") {
					hideAllTags();
				} else if (data.action == "reset-view") {
					resetView();
				} else if (data.action == "change-viewport") {
					resetView();
					StopViewAnimation();
					StartViewAnimation([window.R_config.initView, data.params.position], 1000)
				} else if (data.action == "get-viewport") {
					let tempdata = GetView();
				} else if (data.action == "cctv-item") {
					let tempdata = data.params.row;
					// alert(tempdata);
					addVideoLabel(tempdata);
				} else if (data.action == "remove-cctv-tags") {
					hideAllCctvTags();
				}  
			}

			responseCallback({
				
			});
		});


		/**
		 * 注册了一个函数，提供给Uni-app调用
		 */
		UniJsBridge.registerHandler("test", (data, responseCallback) => {
			console.log("test - from uniapp msg : ")
			console.log(data)
			// data: 是客户端给H5的参数
			// setFromNativeMessage(JSON.stringify(data))
			// 把参数传递给客户端,如果不执行的话，uni-app是无法执行回调的
			responseCallback('我是给uni-app的参数' + Date.now());
		});

		document.querySelector("#clickMe").addEventListener('click', function() {
			console.log("postMessage")
			let temp = GetView();
			console.log(temp)
		})

		UniJsBridge.callHandler(
			"nativeShow", {
				page: "web-index",
				action: "afterinit"
			},
			res => {
				console.log("callHandler - sendback : ")
				console.log(res)
			}
		);

		function hideAllTags() {
			ResetAllElement();
			markerArray.forEach(ele => {
				RemoveMarker(ele);
			});
			markerArray = [];
		}
		
		function clickCCTV(e) {
			UniJsBridge.callHandler(
				"nativeShow", {
					page: "web-index",
					action: "click-cctv",
					Muster:e,
				}
			);
		}
		
		function addVideoLabel(item) {
			const pos = window.GetCenterById(item.glid);
			let htmlStr = `<div class='cctv-tip' onclick='clickCCTV(${item.CType})'>
					<div class="video-img" id="cctv_${item.CType}"></div>
					<p class="cctv-title">${item.Name}</p>
					</div>`
			AddHtmlMarker(pos, htmlStr, 'videoTag'+item.CType);
			cctvMarkerArray.push('videoTag'+item.CType);
		}
		
		function hideAllCctvTags() {
			cctvMarkerArray.forEach(ele => {
				RemoveMarker(ele);
			});
			cctvMarkerArray = [];
		}

		function addLabel(row, glids, type) {
			// testAddHtmlTag();
			// return;

			console.log("addLabel");
			// alert("addLabel");

			// if (markerArray.length >= 1)
			// 	return;

			SetElementColor(glids, 255, 0, 0);
			if (type === "single") {
				ResetAllElement();
				if (markerArray.length > 0) {
					for (var i = 0; i < markerArray.length; i++) {
						RemoveMarker(markerArray[i]);
					}
					markerArray.shift();
				}
				FlyTo(glids, true, 2.8);
			}

			let htmlStr =
				`<div id="tips_show" class='tips_show' onclick="onLabelClick('${row.DeviceName.trim()}','${glids}')">
					<div class="tips_parent">
						
						<image class="tip-icon" src="${getStatus(row)?'./img/1.png':'./img/8.png'} "></image>
						
						<div class="tips-cont">
							<p id='DeviceName_${row.ID}' class='p-text-first'>${row.DeviceName}</p>
							
							<p class="p-text-other" id='QValue_${row.ID}'>${row.QValue}${row.Unit || ""}</p>
						</div>
						
					</div>
				</div>`;

			currentPos = GetCenterById(glids);

			clickGlids = glids;
			AddHtmlMarker(
				currentPos,
				htmlStr,
				"marker" + markerArray.length
			);
			markerArray.push("marker" + markerArray.length);
		}

		function showDetail(row, glids, type) {
			var _obj = document.getElementById("QValue_" + row.ID);
			if (_obj) {
				document.getElementById("QValue_" + row.ID).innerText = row.QValue + (row.Unit || "");
			}
		}

		function getStatus(row) {
			if (
				parseFloat(row.QValue) < parseFloat(row.OfflineValues) ||
				parseFloat(row.QValue) > parseFloat(row.OnlineValue)
			) {
				return true;
			} else {
				return false;
			}
		}
	</script>

</html>
